home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cstrings.arc / STRCPY.C < prev    next >
Text File  |  1985-08-06  |  3KB  |  96 lines

  1. /*
  2.     CSTRINGS.LBR VERSION 1.0
  3.     Spark Software, Inc.
  4.  
  5.         If you find this software of use, it is requested that you send
  6.         a donation ($10.00 suggested) to:
  7.  
  8.             Spark Software, Inc.
  9.             24 Royal Crest Dr., #5
  10.             Nashua, NH  03060
  11.  
  12.         Upon receiving your donation, your name will be added to the 
  13.         List of Registered Users, and future updates can be obtained
  14.         from the SPARKIE RBBS at (603) 888-8179.
  15.  
  16.         If you include an extra $10.00 with your donation, the newest
  17.         version of CSTRINGS.LBR will be mailed to you.
  18.  
  19.         Call SPARKIE RBBS at the number above for other Spark Software
  20.         products!!!
  21. */
  22.  
  23. /*
  24.  *    char *
  25.  *    strcpy (destination, source)
  26.  *    char *destination, *source;
  27.  *
  28.  *    This is an implementation of the UNIX standard function of the
  29.  *    same name.  The characters in source are copied to destination
  30.  *    including the null terminator.    A pointer to the destination is
  31.  *    returned.
  32.  */
  33.  
  34. char *strcpy(destination, source)
  35. register char *destination, *source;
  36. {
  37.     char *start_pointer;
  38.  
  39.                     /* first stash away the original
  40.                        address for the destination
  41.                        since it has to be returned */
  42.     start_pointer = destination;
  43.  
  44.                     /* Now copy until the null terminator
  45.                        is reached */
  46.     while (*destination++ = *source++)
  47.         ;
  48.  
  49.                     /* Return the pointer to the result */
  50.     return (start_pointer);
  51.  
  52. } /* strcpy */
  53.  
  54.  
  55. /*
  56.  *    char *
  57.  *    strncpy (destination, source, length)
  58.  *    char *destination, *source;
  59.  *    int length;
  60.  *
  61.  *    This is an implementation of the UNIX standard function of the
  62.  *    same name.  length characters from source are copied to destination
  63.  *    and the source is null padded or truncated depending on whether
  64.  *    the length of the source is less than, or greater than length. In
  65.  *    the case of length being less than the length of the source, the null
  66.  *    terminator is not added to destination.
  67.  */
  68.  
  69. char *strncpy(destination, source, length)
  70. register char *destination, *source;
  71. register int length;
  72. {
  73.     char *start_pointer;
  74.  
  75.                     /* First save away the pointer to
  76.                        the destination so that it can
  77.                        be returned at the end */
  78.     start_pointer = destination;
  79.  
  80.                     /* Now copy exactly length characters
  81.                        to the destination */
  82.     while (length--)
  83.         if ((*destination++ = *source++) == 0) {
  84.  
  85.                     /* Woops! We reached the end of the
  86.                        source, now null pad the rest */
  87.             while (length--)
  88.                 *destination++ = 0;
  89.             break;
  90.         }
  91.  
  92.                     /* Return a pointer to the result */
  93.     return (start_pointer);
  94.  
  95. } /* strncpy */
  96.